<?php

/**
 * homepage actions.
 *
 * @package    baumarktforsibers.kg
 * @subpackage homepage
 * @author     Belitskii Ivan
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class profileActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
    public function executeRegistration(sfWebRequest $request)
    {
        if ($this->getUser()->isAuthenticated()) {
          $this->getUser()->setFlash('notice', 'You are already registered and signed in!');
          $this->redirect('@viewproducts');
        }

        $this->form = new registrationForm();

        // if Request POST data run Registration from validations
        if ($request->isMethod(sfRequest::POST)) {
            $this->processRegisterForm($request, $this->form);
        }
    }
    
    /**
     * Process register form
     * @param sfRequest $request
     * @param type $form 
     */
    public function processRegisterForm(sfRequest $request, $form) {
        $requestData = $request->getParameter($form->getName());
        $requestData['is_active'] = 1;
        $form->bind($requestData);
        if ($form->isValid()) {

            $user = $form->save();

            $this->getUser()->signin($user, false);
            $this->getUser()->getGuardUser()->save();

            $this->getUser()->setFlash('notice', 'Вы успешно зарегистрированы!');
            // Redirect on homepage
            $this->redirect('@viewproducts');
        }
    }
}